<template>
  <!-- 插槽SLOT-->
  <div class="tab-bar-item" @click="itemclick">
    <slot v-if="!isactive" name="item-icon"></slot>
    <slot v-if="isactive" name="item-icon-active"></slot>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
export default {
  name: 'Tab-Bar-Item',
  props: {
    path: { type: String },
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  data () {
    return {
      // isactive: false 使用计算属性动态获取
    }
  },
  methods: {
    itemclick () {
      // 通过代码修改路由
      // push => pushstate
      // repalce this.$router.repalce('/home')
      console.log('homeclick')
      console.log(this.path)
      this.$router.push(this.path)
    }
  },
  created () {
    console.log(this.$route.path)
    console.log(this.isactive)
  },
  computed: {
    isactive () {
      return this.$route.path.indexOf(this.path) > 0
    },
    activeStyle () {
      return this.isactive ? { color: this.activeColor } : {}
    }
  }
}
</script>

<style scoped>
.tab-bar-item {
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 14px;
}
.tab-bar-item img {
  width: 24px;
  height: 24px;
  margin-top: 3px;
  vertical-align: middle;
  margin-bottom: 2px;
}
</style>
